package com.ougy.customcomponent.draw;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class SimpleLineDrawable extends AbstractDrawable {

	private int direction,color;
	private float length;
	private float width;
	private Paint mPaint;
	private float startX,startY,stopX,stopY;
	public SimpleLineDrawable(float length, int direction, int color, float width) {
		this.length = length;
		this.direction = direction;
		this.color = color;
		this.width = width;
		mPaint = new Paint();
	}

	public SimpleLineDrawable(float length, int direction, int color) {
		this(length, direction, color, 3.0f);
	}

	public SimpleLineDrawable(float length, int direction) {
		this(length, direction, Color.rgb(0, 0, 0));
	}

	public SimpleLineDrawable(float length) {
		this(length, Direction.Horizontal);
	}

	@Override
	public void draw(Canvas canvas) {
		mPaint.setStrokeWidth(width);
		mPaint.setColor(color);
		mPaint.setAntiAlias(true);
		if(direction==Direction.Horizontal){
			startX=-length;
			stopX=length;
		}else if(direction==Direction.VERTICAL){
			startY=-length;
			stopY=length;
		}else{
			throw new RuntimeException("The constructor parameter of direction can't match in this version");
		}
		canvas.drawLine(startX, startY, stopX, stopY, mPaint);
	}

}
